
	'
	'  viewer - simple tool for viewing images inside packages
	'
	'  compile with fbc -s gui viewer.bas
	'
	
	#Include "fbpacker.bi" 	' fbpacker.bi also includes fbgfx.bi...
	
	Dim As Integer 				userInput
	Dim As String					password, inputFile
	Dim As FB.Packer				package
	Dim As FB.IMAGE Pointer		image
	
	ScreenRes 640, 480, 32
	
	Do
	
		Cls
		
		Print
		Input " enter package filename: ", inputFile
		Input " enter password: ", password
		
		If package.Load(inputFile, password) Then
			
			For i As Integer = 0 To package.ItemCount - 1
				
				Cls 
				
				' print image's name/index
				Print package.Item(i)->Name; ": image "; (i + 1); " of "; package.ItemCount
				
				' get image from package (do NOT ImageCreate before this or you'll get memory leak)
				image = package.ExtractImage(package.Item(i)->Name)
				
				' blit it to screen
				Put ((640 - image->width) / 2, (480 - image->height) / 2), image, PSet
				
				' destroy it
				ImageDestroy image
				
				Sleep ' wait for key press
				
			Next
			
		EndIf
		
		Print
		Print " What you want to do now:"
		Print
		Print "  [1] Unpack more packages!"
		Print "  [anything else] Exit"
		Print
		Input "> ", userInput
		
		package.Clear
		
		If userInput = 1 Then Continue Do
		
		Exit Do
	
	Loop
	